import { _decorator, Color, director, isValid, Label, Sprite, tween } from 'cc';
import { SceneEnum } from '../Enum';
import DataManager from '../Runtime/DataManager';
import { ObjectPoolManager } from '../Runtime/ObjectPoolManager';
import { UIComponent } from '../Base/UIComponent';
const { ccclass, property } = _decorator;

@ccclass('GameOverUI')
export class GameOverUI extends UIComponent {

    maskSp: Sprite
    lab_cai: Label
    btn: Sprite

    show() {
        this.node.active = true

        this.maskSp = this.node.getChildByName('mask').getComponent(Sprite)
        this.lab_cai = this.node.getChildByName('Label').getComponent(Label)
        this.btn = this.node.getChildByName('Button').getComponent(Sprite)

        this.maskSp.color = new Color(255, 255, 255, 0)
        this.lab_cai.color = new Color(255, 255, 255, 0)
        this.btn.color = new Color(255, 255, 255, 0)

        const color = new Color(0, 0, 0, 0)
        tween(color)
            .delay(0.5)
            .to(1, { a: 255 }, {
                onUpdate: () => {
                    if (!isValid(this.node, true)) return
                    this.maskSp.color = color
                }
            })
            .call(() => {
                color.set(255, 0, 0, 0)
            })
            .to(1, { a: 255 }, {
                onUpdate: () => {
                    if (!isValid(this.node, true)) return
                    this.lab_cai.color = color
                }
            })
            .call(() => {
                color.set(255, 255, 255, 0)
            })
            .to(1, { a: 255 }, {
                onUpdate: () => {
                    if (!isValid(this.node, true)) return
                    this.btn.color = color
                }
            })
            .start()

    }

    onClick() {
        director.loadScene(SceneEnum.Login, () => {
            DataManager.Ins.reset()
            ObjectPoolManager.Ins.reset()
        })
    }

}


